<?php

namespace Agp\CoreBundle\Entity;

use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Agp\CoreBundle\Validator\Constraints as CoreAssert;
use Doctrine\Common\Collections\ArrayCollection;
use APY\DataGridBundle\Grid\Mapping as GRID;

/**
 * Agp\CoreBundle\Entity\Repasse
 *
 * @ORM\Table(name="repasse")
 * @ORM\Entity(repositoryClass="Agp\CoreBundle\Repository\RepasseRepository")
 * 
 * @GRID\Source(columns="codRepasse, evento.info.descricao, responsavel.nome, dt, situacao, vlrSolicitado, vlrRepassado")
 * @CoreAssert\RepasseVlrDisponivel
 * 
 */
class Repasse
{
    /**
     * @var integer $codRepasse
     *
     * @ORM\Column(name="cod_repasse", type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     * 
     * @GRID\Column(title="Código", type="text", size="5", primary=true, visible=false)
     */
    protected $codRepasse;
    
    /**
     * @var object $empresa
     *
     * @ORM\ManyToOne(targetEntity="Empresa", fetch="LAZY")
     * @ORM\JoinColumn(name="cod_empresa", referencedColumnName="cod_empresa", onDelete="Cascade", nullable=false)
     */
    protected $empresa;
            
    /**
     * @var object $evento
     *
     * @ORM\ManyToOne(targetEntity="Evento", fetch="LAZY")
     * @ORM\JoinColumn(name="cod_evento", referencedColumnName="cod_evento", onDelete="Cascade", nullable=true)
     * 
     * @GRID\Column(field="evento.info.descricao", title="Evento", type="text")
     */
    protected $evento;
    
    /**
     * @var object $responsavel
     *
     * @ORM\ManyToOne(targetEntity="Pessoa", fetch="LAZY")
     * @ORM\JoinColumn(name="cod_pessoa", referencedColumnName="cod_pessoa", onDelete="Cascade", nullable=false)
     * @Assert\NotBlank(groups={"agape"})
     * 
     * @GRID\Column(field="responsavel.nome", title="Responsável", type="text")
     */
    protected $responsavel;  
    
    /**
     *
     * @var datetime
     * 
     * @ORM\Column(type="datetime", nullable=false)
     * 
     * @GRID\Column(title="Data", type="datetime", align="center")
     */
    protected $dt;
    
    /**
     * @var float $vlr
     *
     * @ORM\Column(name="vlr_solicitado", type="float", nullable=true)
     * @Assert\NotBlank
     * 
     * @GRID\Column(title="Valor Solicitado", type="number", style="currency")
     */
    protected $vlrSolicitado;
    
    /**
     * @var float $vlr
     *
     * @ORM\Column(name="vlr_repassado", type="float", nullable=true)
     * @Assert\NotBlank
     * 
     * @GRID\Column(title="Valor Repassado", type="number", style="currency")
     */
    protected $vlrRepassado;
    
    const SIT_ATIVO = 'Ativo';
    const SIT_PENDENTE = 'Pendente';
    const SIT_ULTIMO = 'Ultimo';
    
    /**
     * @var string $situacao
     *
     * @ORM\Column(name="situacao", type="string", nullable=false)
     * 
     * @GRID\Column(title="Situação", type="text", align="center", filter="select", selectFrom="source")
     */
    protected $situacao;

    /**
     * @var object $responsavel
     *
     * @ORM\ManyToOne(targetEntity="SolicitacaoRepasse", fetch="LAZY")
     * @ORM\JoinColumn(name="cod_solicitacao_repasse", referencedColumnName="cod_solicitacao_repasse", onDelete="Cascade", nullable=true)
     * 
     */
    protected $solicitacaoRepasse;
    
    public function __construct() {
        $this->dt = new \DateTime;
        $this->situacao = self::SIT_ATIVO;
        $this->vlrSolicitado = 0;
        $this->vlrRepassado = 0;
        $this->pedidos = new ArrayCollection;
    }

    public function getCodRepasse() {
        return $this->codRepasse;
    }

    public function setCodRepasse($codRepasse) {
        $this->codRepasse = $codRepasse;
    }

    public function getEmpresa() {
        return $this->empresa;
    }

    public function setEmpresa($empresa) {
        $this->empresa = $empresa;
    }

    public function getEvento() {
        return $this->evento;
    }

    public function setEvento($evento) {
        $this->evento = $evento;
    }

    public function getDt() {
        return $this->dt;
    }

    public function setDt($dt) {
        $this->dt = $dt;
    }

    public function getResponsavel() {
        return $this->responsavel;
    }

    public function setResponsavel($responsavel) {
        $this->responsavel = $responsavel;
    }
    
    public function getSituacao() {
        return $this->situacao;
    }

    public function setSituacao($situacao) {
        $this->situacao = $situacao;
    }
    
    public function getVlrSolicitado() {
        return $this->vlrSolicitado;
    }

    public function setVlrSolicitado($vlrSolicitado) {
       $this->vlrSolicitado = substr(str_replace(",", ".", $vlrSolicitado),3);
            
    }
    
    public function setVlrSolicitadoNotSubstring($vlrSolicitado){
        $this->vlrSolicitado = $vlrSolicitado;
    }

    public function getVlrRepassado() {
        return $this->vlrRepassado;
    }

    public function setVlrRepassado($vlrRepassado) {
        $this->vlrRepassado = $vlrRepassado;
    }
    
    public static function getSituacaoList(){
        return array(self::SIT_ATIVO => self::SIT_ATIVO,
                     self::SIT_PENDENTE => self::SIT_PENDENTE);
    }
    
    public function getPedidos() {
        return $this->pedidos;
    }

    public function setPedidos($pedidos) {
        $this->pedidos = $pedidos;
    }
    
    public function getSolicitacaoRepasse() {
        return $this->solicitacaoRepasse;
    }

    public function setSolicitacaoRepasse($solicitacaoRepasse) {
        $this->solicitacaoRepasse = $solicitacaoRepasse;
    }



}
